// components/type-select/type-select.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        type: {
            type: String,
            value: "login"
        },

        selected: {
            type: Number,
            value: 0
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        _actionSheet: { //类型选择
            show: false,
            list: [{
                type: 1,
                name: "个人客户",
            }, {
                type: 2,
                name: "机构客户",
            }, {
                type: 3,
                name: "产品客户"
            }],
            current: {}
        },
    },

    /*
    * 监听
    * */
    observers: {
        type: function (val) {
            if (val !== "login") {
                let list = this.data._actionSheet.list;
                this.setData({
                    "_actionSheet.list": list.splice(0, list.length - 1)
                })
            }
        },
        "selected": function (val) {
            if (val) {
                let list = this.data._actionSheet.list;
                this.setData({
                    "_actionSheet.current": list.filter(function (item) {
                        return parseInt(val) === item.type
                    })[0]
                })
            }
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        bindTypeClick: function () {
            this.setData({"_actionSheet.show": true})
        },
        onActionSheetClose: function () {
            this.setData({"_actionSheet.show": false})
        },
        onActionSheetSelect: function (e) {
            this.triggerEvent("typeSelect", e.detail, {});
            this.setData({"_actionSheet.current": e.detail})
        },
    }
})
